import moment from "moment";
export class Date {
  constructor() {
    this._selectedDate = "";
    this._selectedTime = "";
  }

  set selectedDate(newval) {
    this._selectedDate = newval;
  }

  get selectedDate() {
    return this._selectedDate;
  }

  set selectedTime(newval) {
    this._selectedTime = newval;
  }

  get selectedTime() {
    return this._selectedTime;
  }

  get thisTime() {
    return moment().format();
  }
  get todayDate() {
    return moment().format("YYYY-MM-DD");
  }

  get isOfDuty() {
    return moment().hour() > 18;
  }
  get nextWeeks() {
    const sliceArg = this.isOfDuty ? [1, 8] : [0, 7];
    return [0, 1, 2, 3, 4, 5, 6, 7].slice(...sliceArg).map((item) =>
      moment()
        .add(item, "days")
        .format("YYYY-MM-DD")
    );
  }

  get times() {
    const arr = [];
    for (let i = 8; i < 18; i++) {
      if (i == 12 || i == 13) continue;
      arr.push(`${i}:00`, `${i}:30`);
    }
    return arr;
  }

  get appointableTime() {
    if (this.selectedDate) {
      if (this.selectedDate == this.todayDate) {
        return this.times.filter(
          (item) => Number(item.split(":")[0]) > Number(moment().hour())
        );
      } else {
        return this.times;
      }
    } else {
      return ["请选择日期"];
    }
  }
  get test() {
    console.log(this.appointableTime);
  }
}
